<template>
  <div class="index-box" ref="index">
     <!-- <div class="menuList" ref="menuList">
        <div class="menu-item"  v-for="(item,index) in menuList">
          <div class="numberBox">
            <span class="number">{{item.count}}</span>
          </div>
          <div class="text">{{item.msg}}</div>
          <div class="menuActive" v-if="index=='4'" @click="handleUpMoneyApply">提额申请</div>
          <div class="menuActive" v-else-if="index=='5'" @click="handleUpMoneyDetail">提额明细</div>
        </div>
      </div> -->
        <div class="search" ref="search">
         <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent
           class="demo-form-inline" id="searchBox">
           <el-form-item prop="orderNo">
               <el-input v-model="searchForm.orderNo" clearable placeholder="请输入订单编号"></el-input>
           </el-form-item>
           <el-form-item prop="goodsName">
               <el-input v-model="searchForm.goodsName" clearable placeholder="请输入商品名称"></el-input>
           </el-form-item>
           <el-form-item prop="payTime">

             <el-date-picker v-model="payTime" type="daterange" align="right" unlink-panels range-separator="至"
               start-placeholder="付款开始日期" end-placeholder="付款结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
               :picker-options="pickerOptions">
             </el-date-picker>
           </el-form-item>
           <!-- <el-form-item prop="settleTime">
             <el-date-picker v-model="settleTime" type="daterange" align="right" unlink-panels range-separator="至"
               start-placeholder="结算开始日期" end-placeholder="结算结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
               :picker-options="pickerOptions">
             </el-date-picker>
           </el-form-item> -->
           <el-form-item class="clearfix">
             <el-button type="primary" @click="handleSearch()" icon="el-icon-search">查询</el-button>
             <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
           </el-form-item>
         </el-form>
        </div>

        <div class="table orderTabel" ref="table">
          <el-table :data="dataList" style="width: 100%" row-key="orderNo" v-loading="loading" border :height="tableHeight" @selection-change="handleSelectionChange" default-expand-all>

            <el-table-column type="expand">
              <template slot-scope="scope">
                <div class="item-box d-flex">
                  <div class="item-box-item-1 d-flex" v-if="!hideTableColumn.includes('img')">

                    <TableShopBox :row="scope.row.goodsInfo" :index="scope.$index"/>
                  </div>

                  <div class="align-center justify-center d-flex" style="width:100px" v-if="!hideTableColumn.includes('userImg')">
                       <el-image :src="scope.row.userface" fit="fill" v-image-preview="scope.row.userface" class="img"></el-image>
                  </div>
                  <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('phone')">
                      {{scope.row.telephone}}
                  </div>
                  <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('allMoney')">
                      {{scope.row.goodsTotalPrice}}
                  </div>
                  <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('payMoney')">
                      {{scope.row.actualPayPrice}}
                  </div>
                  <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('closeMoney')">
                      {{scope.row.amountReceived}}
                  </div>
                  <div class="align-center justify-center d-flex flex1" v-if="!hideTableColumn.includes('status')">
                      <el-tag :type="scope.row.settlementStatus=='1'?'primary':'success'">{{scope.row.settlementStatus=='1'?'待退款':'已退款'}}</el-tag>
                  </div>

                </div>
              </template>
            </el-table-column>
             <el-table-column prop="name" label="商品" v-if="!hideTableColumn.includes('img')" width="700" align="center">
               <template #default="scope">
                <div class="d-flex">
                  <span class="font-size-13 color-999">订单编号:{{ scope.row.orderCode }}</span>
                  <span class="font-size-13 color-999 margin-left-10">订单类型:{{ scope.row.orderTypeName }}</span>
                  <span class="font-size-13 color-999 margin-left-10">付款时间:{{ parseTime(scope.row.paymentTime) }}</span>
                </div>
               </template>
             </el-table-column>
             <el-table-column align="center" prop="" label="用户头像" v-if="!hideTableColumn.includes('userImg')" width="100"></el-table-column>
             <el-table-column align="center" prop="" label="用户手机号" v-if="!hideTableColumn.includes('phone')" width="160"></el-table-column>
             <el-table-column align="center" prop="" label="商品总金额(元)" v-if="!hideTableColumn.includes('allMoney')" width="160"></el-table-column>
             <el-table-column align="center" prop="" label="实付金额(元)" v-if="!hideTableColumn.includes('payMoney')" width="160"></el-table-column>
             <el-table-column align="center" prop="" label="实收金额(元)" v-if="!hideTableColumn.includes('closeMoney')" width="160"></el-table-column>
             <el-table-column align="center" prop="" label="退款状态" v-if="!hideTableColumn.includes('status')" ></el-table-column>

          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
             :total="total"
             :page.sync="searchForm.pageNum"
             :limit.sync="searchForm.pageSize"
             @pagination="dataInfo"
           />
        </div>

      <!-- /*提额申请*/	 -->
      <el-dialog title="提额申请" width="600px" v-dialogDrag :visible.sync="upMoneyVisible" @close="upMoneyVisible = false">
        <el-form class="formDialog"  label-position="right" :model="upMoneyForm"  :rules="upMoneyRules" ref="upMoneyForm" >
          <el-form-item label="真实姓名:" prop="name" label-width="125px" style="width:100%" >
             xxx
          </el-form-item>
          <el-form-item label="手机号:" prop="name" label-width="125px" style="width:100%">
             xxx
          </el-form-item>
          <el-form-item label="可提金额:" prop="name" label-width="125px" style="width:100%">
             <span>2000</span>元
          </el-form-item>
          <el-form-item label="申请提取金额:" prop="money" label-width="125px" style="width:100%">
              <el-input v-model="upMoneyForm.money" clearable placeholder="最多可提取500.00"  style="width:200px;margin-right:5px"></el-input>元
          </el-form-item>
          <el-form-item label="实际到账金额:" prop="name" label-width="125px" style="width:100%">
             <span>2000</span>元
          </el-form-item>
          <el-form-item label="备注信息:" prop="name" label-width="125px" style="width:100%">
             <el-input v-model="upMoneyForm.remark" clearable placeholder="请输入备注"  type="textarea" ></el-input>
          </el-form-item>
          <el-form-item label="提额说明:" prop="name" label-width="125px" style="width:100%">
            <p class="tips">1、操作提额后，经平台评估通过后才可结算;</p>
            <p class="tips">2、每提次输入的金额必须大于1000元;</p>
            <p class="tips">3、每笔提额需收取3%的服务费，每月最多提额3次。</p>
          </el-form-item>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="upMoneyVisible = false" size="small">取 消</el-button>
          <el-button type="primary" @click="submitupMoney('upMoneyForm')" size="small" :loading="userLoading">确 定</el-button>
        </div>
      </el-dialog>



  </div>
</template>

<script>
  import { isCard,isPhone,isEmail } from '../../common/validate.js';
  import common from '@/api/api';
  import {orderRefundGetList,getRefundTotalAmount} from '@/api/getData'
  import option from '../../common/option.js';
  import { regionData,CodeToText } from 'element-china-area-data';
	import TableShopBox from '@/views/order/components/tableShopBox'
  export default {
  	components: {
       TableShopBox
    },
    data() {
      return {
        loading: false,
        userLoading: false,
        cascaderOptions:regionData,/*省市区插件数据*/
        menuIndexStatus:'0',
        menuList:[
          {msg: "待退款总额", count: 0, orderStatus: 1},
          {msg: "已退款总额", count: 0, orderStatus: 4},
         ],
//        {msg: "可提金额(元)", count: 0, orderStatus: 5},
//        {msg: "已提金额(元)", count: 2, orderStatus: 0}
          payTime:[],
          settleTime:[],
          order_type_key:[],
          settlementStatusList:[{name:"待结算",id:'1'},{name:"已结算",id:'2'}],
        searchForm: {
          orderNo: '',
          goodsName: '',
          settlementStatus:'',
          orderType:'',

          pageNum: 1,
          pageSize: 20,
        },
        tableColumn:[{
            name:'商品',
            value:'img'
        },{
            name:'用户头像',
            value:'userImg'
        },{
            name:'用户手机号',
            value:'phone'
        },{
            name:'商品总金额(元)',
            value:'allMoney'
        },{
            name:'实付金额(元)',
            value:'payMoney'
        },{
            name:'实收金额(元)',
            value:'closeMoney'
        },{
            name:'退款状态',
            value:'status'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:400,//table 高度
        dataList:[],
        total: 0,
        multipleSelection: '',
        dialogTitle: '',

        upMoneyVisible:false,//评价详情
        upMoneyForm:{
          money:'',
          remark:''
        },
        upMoneyRules:{
          money: [{required: true, message: '请输入申请提取金额',trigger: 'blur'}]
        },
      }
    },
    computed: {
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      // this.getSelect();
       this.dataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight   - this.$refs.search.offsetHeight - this.$refs.page.offsetHeight - 75;
      })
    },
    methods: {
      async dataInfo() {
        try {
          let data = this.addDateRange(this.searchForm, this.payTime,'startPayTime','endPayTime');
          // data = this.addDateRange(this.searchForm, this.settleTime,'settleStartTime','settleEndTime');
          this.loading = true;
          const result = await orderRefundGetList(data);
          if (result.code == 200) {
            this.total = result.total;
            this.dataList = result.rows;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },
      getSelect(){

        this.getSelectList('order_type_key').then(res=>{ this.order_type_key = res.data; })
        getRefundTotalAmount().then(res=>{
          if(res.data){
            this.menuList[0].count = res.data.orderTotalFee;
            this.menuList[1].count = res.data.refundTotalFee;
          }
        })
      },
      addressChange(arr) {
          console.log(arr);
          console.log(CodeToText[arr[0]], CodeToText[arr[1]], CodeToText[arr[2]]);
          this.editAddr.provinceId = arr[0]+'000000';
          this.editAddr.cityId = arr[1]+'000000';
          this.editAddr.areaId = arr[2]+'000000';
      },

      handleUpMoneyApply(){
        this.upMoneyVisible = true;
      },
      submitupMoney(formName) {/*申请提额提交*/
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.userLoading = true;
            getCallRecord(this.user).then((result) => {
              if (result.success == true) {
                this.$message.success(result.message);
                this.userFormVisible = false;
                this.dataInfo();
              } else {
                this.$message.error(result.message);
              }
              this.userLoading = false;
            });
          }
        })
      },
      handleUpMoneyDetail(){
        this.$router.push({path:'/finance/upMoneyDetail',query:{setid:123456}});
      },
      handleDetail(row){/*查看详情*/
          this.rateVisible = true;
      },
      handleGoAfterSale(row){/*查看售后信息*/
        orderGetAfterSaleInfo({orderId:row.orderId}).then((result) => {
          this.afterInformationList = result.data[0];
        });
        this.userFormVisible = true;
      },

      handleShipments(row){//发货
        this.shipmentsVisible = true;
      },
      submitShipments(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.userLoading = true;
            getCallRecord(this.user).then((result) => {
              if (result.success == true) {
                this.$message.success(result.message);
                this.userFormVisible = false;
                this.dataInfo();
              } else {
                this.$message.error(result.message);
              }
              this.userLoading = false;
            });
          }
        })
      },
      handleEditAddr(row){//修改地址
        this.editAddrVisible = true;
      },
      submiteditAddr(formName) {/*修改地址提交*/
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.userLoading = true;
            getCallRecord(this.user).then((result) => {
              if (result.success == true) {
                this.$message.success(result.message);
                this.userFormVisible = false;
                this.dataInfo();
              } else {
                this.$message.error(result.message);
              }
              this.userLoading = false;
            });
          }
        })
      },

      handleRefund(row){//确定退款
        this.$confirm(`您确定将订单号为<span class="red">${row.name}</span>操作退款吗？`, '确定退款', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         dangerouslyUseHTMLString: true,
         type: 'warning'
        }).then(() => {
         getCallRecord(this.user).then((result) => {
           if (result.success == true) {
             this.$message.success(result.message);
             this.userFormVisible = false;
             this.dataInfo();
           } else {
             this.$message.error(result.message);
           }
           this.userLoading = false;
         });
       }).catch(() => {});
      },
      handleExchange(row){//确定换货
        this.$confirm(`您确定将订单号为<span class="red">${row.name}</span>操作换货吗？`, '确定换货', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          dangerouslyUseHTMLString: true,
          type: 'warning'
         }).then(() => {
          getCallRecord(this.user).then((result) => {
            if (result.success == true) {
              this.$message.success(result.message);
              this.userFormVisible = false;
              this.dataInfo();
            } else {
              this.$message.error(result.message);
            }
            this.userLoading = false;
          });
        }).catch(() => {});

      },
      /** 重置按钮操作 */
      resetQuery() {
        this.payTime = [];
        this.settleTime = [];
        this.resetForm("searchForm");
        this.dataInfo();
      },
      handleItem(id){
        this.searchForm.orderStatus = id;
        this.dataInfo();
      },
      handleSearch() {
        this.searchForm.pageNum = 1;
        this.dataInfo();
      },
      submitUser(formName) {
        /*添加用户*/
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.userLoading) return;
            this.userLoading = true;
            getCallRecord(this.user).then((result) => {
              if (result.success == true) {
                this.$message.success(result.message);
                this.userFormVisible = false;
                this.dataInfo();
              } else {
                this.$message.error(result.message);
              }
              this.userLoading = false;
            });
          }
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    }
  }
</script>

<style scoped lang="scss">
  .orderTabel /deep/ .el-table__row {
     background: #FAFCFB !important;
      height: 36px !important;
      td{
        padding:0px;
        height:30px;
      }
  }
  .orderTabel .el-table td .cell {
      height: 30px;
      display: flex;
      align-items: center;
  }
  .item-box {
      color: #444;
      padding:10px 0;
  }
  .item-box-item-1{
     width: 700px;
     //padding: 16px 14px 14px;
  }
  .orderTabel /deep/ .el-table__expanded-cell{
    background-color: #fff!important;
  }
  .orderTabel /deep/ .el-table__cell.el-table__expanded-cell{
    padding-right:0px;
  }




  .tips{
    margin:0px;
  }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .menuList{
      display: flex;
      margin-bottom: 15px;
      .menu-item{
        flex:1;
        padding:20px 20px 10px 20px;
        border:1px solid #DCDFE6;
        border-right: none;
        cursor: pointer;
        .numberBox{
          display:flex;
          justify-content:center;
        }
        .tipsNumber{
           font-size: 12px;
           height: 18px;
           line-height: 18px;
           padding: 0 6px;
           text-align: center;
           white-space: nowrap;
           position:absolute;
           background:#FF2F43;
           border-radius: 10px;
           right: -16px;
           top: -6px;
           color:#fff;
        }
        .number{
          font-size: 32px;
          position:relative;
        }
        .text{
          font-size: 16px;
          color:#333333;
          text-align: center;
        }
      }
    }
    .menuList .menu-item:last-child{
      border-right: 1px solid #DCDFE6;
    }
    .table /deep/ .el-table__expanded-cell{
     background: #FAFCFB;
      padding:0 50px;
    }
    .table /deep/ .el-table__expanded-cell:hover{
     background: #FAFCFB!important;
    }
    .table /deep/ .el-table__expanded-cell .el-form-item{
      margin-bottom: 0px;
      margin-right: 30px;
    }
    .table /deep/ .el-table__expanded-cell .el-form-item__label,.table /deep/ .el-table__expanded-cell .el-form-item__content{
       height: 54px;
       line-height: 54px;
    }
    .menuActive{
      text-align: center;
      color:#3A7654;
      cursor: pointer;
      padding:10px 0;
    }
</style>
